package com.sgcc.ln.pmos.e_ln_order.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RelativeLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.sgcc.ln.pmos.common.base.BaseRecyclerAdapter;
import com.sgcc.pmos.nativesdk.R;

public class MonthAdapter extends BaseRecyclerAdapter<String> {

    private Context mContext;
    private int selectPosition = 0;

    public void setSelectPosition(int selectPosition) {
        this.selectPosition = selectPosition;
        notifyDataSetChanged();
    }

    public int getSelectPosition() {
        return selectPosition;
    }

    public MonthAdapter(Context context) {
        this.mContext = context;
    }

    @Override
    public RecyclerView.ViewHolder onCreate(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_month, parent, false);
        return new MonthHolder(view);
    }

    @Override
    public void onBind(RecyclerView.ViewHolder viewHolder, int position, String s) {
        MonthHolder holder = ((MonthHolder) viewHolder);
        if (selectPosition == position) {
            holder.mRlMonth.setBackgroundResource(R.drawable.bg_month_true);
        } else {
            holder.mRlMonth.setBackgroundResource(R.drawable.bg_month_false);
        }
        holder.mTvMonth.setText(s);
    }

    public class MonthHolder extends RecyclerView.ViewHolder {

        private RelativeLayout mRlMonth;
        private TextView mTvMonth;

        public MonthHolder(@NonNull View itemView) {
            super(itemView);
            mRlMonth = (RelativeLayout) itemView.findViewById(R.id.rl_month);
            mTvMonth = (TextView) itemView.findViewById(R.id.tv_month);
        }
    }
}
